//
//  RootTabBarViewController.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/5.
//  Copyright © 2017年 tml. All rights reserved.
//

import UIKit

class RootTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //由于tabbarUI图的颜色 跟系统的不搭配，所以进行isTranslucent处理
        tabBar.isTranslucent = false
        addChildViewVontrollers()
        
        // Do any additional setup after loading the view.
    }

    fileprivate func addChildViewVontrollers() {
        addChildViewController(childController: HomeViewController(), title: "首页", imageName: "tab_home", selectedImage: "tab_home_S")
        addChildViewController(childController: CateViewController(), title: "分类", imageName: "tab_class", selectedImage: "tab_class_S")
        addChildViewController(childController: BookshelfViewController(), title: "书架", imageName: "tab_book", selectedImage: "tab_book_S")
        addChildViewController(childController: MineViewController(), title: "我的", imageName: "tab_mine", selectedImage: "tab_mine_S")
    }
    
    fileprivate func addChildViewController(childController:UIViewController, title:String, imageName:String, selectedImage:String) {
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: selectedImage)?.withRenderingMode(.alwaysOriginal)
        //由于tabbar切图是图片文字一起 ，所以对文字，image偏移量处理
        childController.title = nil
        if UIDevice.current.userInterfaceIdiom == .phone {
            childController.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0)
        }
        
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)

        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}


